﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileDB;
namespace Rem.Objects.Forms
{
    public partial class EmployeeForm : BaseForm
    {
        public const string TextTemplate = "员工#{0}-{1}";
        public EmployeeForm(Employee employee)
            : this(string.Format(TextTemplate, employee.Id, employee.Name))
        {
            this.ucEmployee1.Data = employee;
        }

        public EmployeeForm(string text)
            : base(text)
        {
            InitializeComponent();
            this.Text = text;
            this.ucEmployee1.Saved += new EventHandler(ucEmployee1_Saved);
            this.ucEmployee1.Deleted += new EventHandler(ucEmployee1_Deleted);
        }

        public EmployeeForm()
            : this("新建员工")
        {

        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            this.ucEmployee1.Save();
        }

        private void btrnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
        
        public override BaseObjectTypes BaseType
        {
            get
            {
                return BaseObjectTypes.Employee;
            }
        }

        public void ucEmployee1_Saved(object sender, EventArgs e)
        {
            Employee employee = sender as Employee;
            this.Text = string.Format(TextTemplate, employee.Id, employee.Name);
        }

        public void ucEmployee1_Deleted(object sender, EventArgs e)
        {
            this.Close();
        }
        
    }
}
